function [lat,lon,ellh] = GetLonLat(statName)
%GetLonLat - get geodetic coordinates from Nevada Geodetic Laboratory
%
%       [Lat,Lon,ellH] = GetLonLat(STATNAME)
%
% This function takes latitude Lat, longitude Lon and heigh (with respect
% to ellypsoid) ellH of the station STATNAME (four characters) form the
% Nevada Geodetic Laboratory web site.

% G. Teza, 2021

statName = upper(statName);

CommonUrl = 'http://geodesy.unr.edu/NGLStationPages/stations/';
ComplUrl = [CommonUrl statName '.sta'];

try
    h = webread(ComplUrl);
    allok = true;
catch
    allok = false;
end
if ~allok 
    lat = [];
    lon = [];
    ellh = [];
    fprintf('Warning: no data about station %s\n',statName);
    return
end

% undesired markup removal by using regular expressions:
txt = regexprep(h,'<script.*?/script>','');
txt = regexprep(txt,'<style.*?/style>','');
txt = regexprep(txt,'<.*?>','');

% string segment selection:
I1 = strfind(txt,'Latitude');
I2 = strfind(txt,'meters');
txtr = txt(I1:I2);
J1 = strfind(txtr,'Longitude');
J2 = strfind(txtr,'Height');

txtLa = txtr(1:J1);
KLa1 = strfind(txtLa,':');
KLa2 = strfind(txtLa,'degrees');
lat = str2double(txtLa(KLa1+1:KLa2-1));

txtLo = txtr(J1:J2);
KLo1 = strfind(txtLo,':');
KLo2 = strfind(txtLo,'degrees');
lon = str2double(txtLo(KLo1+1:KLo2-1));

txtH = txtr(J2:end);
KH1 = strfind(txtH,':');
KH2 = strfind(txtH,'m');
ellh = str2double(txtH(KH1+1:KH2-1));